package com.cqeec.view;

import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.cqeec.service.TeacherService;
import com.cqeec.service.imp.TeacherServiceImpl;
import com.cqeec.utils.JDBCUtils;
/**
 * 查看请假界面
 * @author Administrator
 *
 */
public class SeeLeave extends JInternalFrame {
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SeeLeave frame = new SeeLeave();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SeeLeave() {
		setIconifiable(true);
		setClosable(true);
		setTitle("查看请假");
		setBounds(100, 100, 686, 451);
		
		JScrollPane attendance = new JScrollPane();
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(attendance, GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE)
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(44)
					.addComponent(attendance, GroupLayout.PREFERRED_SIZE, 230, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(141, Short.MAX_VALUE))
		);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u73ED\u7EA7", "\u5B66\u53F7", "\u8BFE\u7A0B\u4EE3\u53F7", "\u8BF7\u5047\u65F6\u95F4", "\u8BF7\u5047\u539F\u56E0"
			}
		));
		attendance.setViewportView(table);
		getContentPane().setLayout(groupLayout);
		this.allselect();

	}
	public void allselect() {
		JDBCUtils jdbc=new JDBCUtils();
		Connection con=jdbc.getConnection();
		TeacherService service=new TeacherServiceImpl();
		
		DefaultTableModel dt=(DefaultTableModel) table.getModel();
		dt.setRowCount(0);//表格设置初始化
		
		try {
			     ResultSet rs = service.getleave(con);
			
			while(rs.next()){
				Vector<Object> v = new Vector<Object>();
				
				v.add(rs.getString("courseNum"));
				v.add(rs.getString("classes"));
				v.add(rs.getString("vacationDate"));
				v.add(rs.getString("vacationCause"));
				v.add(rs.getString("studentNum"));
				
				dt.addRow(v);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	
	}
}
